// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameMain extends cc.Component {

    timer: number = 0;
    static score:number = 0;
@property(cc.Label)
scoreLabel:cc.Label = null;
    @property(cc.Prefab)
    enemy:cc.Prefab = null;
    @property(cc.Node)
    resetLabel:cc.Node = null;
    static running:boolean = false;
    start () {
        cc.director.getCollisionManager().enabled = true; // 开启碰撞检测 全局的，在程序运行时任何一个地方开启即可
        this.reset();
    }

    reset(){
        GameMain.running = true;
        GameMain.score = 0;
        this.resetLabel.active = false;
    }

    update(dt: number){
        this.timer ++;
        // console.log("射击GamaMain.update" + this.timer);
        if (GameMain.running && this.timer % 60 == 0) {
            let loadobj = cc.instantiate(this.enemy);//将预制体克隆到场景
            this.node.addChild(loadobj);//将克隆出的物体作为子物体
            loadobj.setPosition(new cc.Vec2(1000,90000));
        }
        this.scoreLabel.string = GameMain.score.toString();
        if (!GameMain.running) {
            this.resetLabel.active = true;
        }
    }


}
